package com.candoit.webapps.pricing.controllers;

import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import com.candoit.webapps.pricing.model.Perfil;
import com.candoit.webapps.pricing.model.Rol;
import com.candoit.webapps.pricing.util.QueryUtil;

@ManagedBean(name = "profileCtrl")
@SessionScoped
public class ProfileController extends AbstractController{
	
	private List<Perfil> profiles;
	
	private Perfil profileSelected;
	
	private List<Rol> roles;
	
	public List<Perfil> getProfiles() {
		profiles = QueryUtil.getInstance().getPerfiles();
		
		return profiles;
	}

	public void setProfiles(List<Perfil> profiles) {
		this.profiles = profiles;
	}

	public Perfil getProfileSelected() {
		if (profileSelected == null){
			profileSelected = new Perfil();
		}
		return profileSelected;
	}

	public void setProfileSelected(Perfil profileSelected) {
		this.profileSelected = profileSelected;
	}

	public void savePerfil(){
		this.save(profileSelected);
		profileSelected = null;
		
	}
	
	public void removePerfil(){
		this.remove(profileSelected);
		profileSelected = null;
	}
	
	public void clearData(){
		this.saveSuccess = false;
		this.deleteSuccess = false;
		this.profileSelected = null;
		this.error = false;
		this.message = null;
	}

	public List<Rol> getRoles() {
		if (roles == null){
			roles = QueryUtil.getInstance().getRoles();
		}
		return roles;
	}

	public void setRoles(List<Rol> roles) {
		this.roles = roles;
	}
	
	
	
//	private void fillProfiles(List<Perfil> lista){
//		profiles = new ArrayList<UtilPerfil>();
//		Iterator<Perfil> it = lista.iterator();
//		while (it.hasNext()){
//			   Perfil perfil = (Perfil) it.next();
//			   UtilPerfil util = new UtilPerfil();
//			   util.setPerfil(perfil);
//			   util.setSelected(false);
//			   profiles.add(util);
//		}
		
//		UtilPerfil utilPerfil = new UtilPerfil();
//		Perfil perfil = new Perfil();
//		utilPerfil.setPerfil(perfil);
//		utilPerfil.setSelected(true);
//		profiles.add(utilPerfil);
//	}
	
	
	
}
